home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / what.zip / HELPEX.C_ / HELPEX.bin
Text File  |  1992-08-06  |  20KB  |  692 lines

  1. /****************************************************************************
  2.  
  3.    PROGRAM:    HelpEx.c
  4.  
  5.    PURPOSE:    Illustrates calls to WinHelp and context-sensitive help.
  6.                HelpEx loads library MenuHook, which detects F1 keystrokes in
  7.                the HelpEx application menus.
  8.  
  9.    FUNCTIONS:
  10.  
  11.    WinMain() - Calls initialization function, processes message loop.
  12.    InitApplication() - Initializes window data and registers window class.
  13.    InitInstance() - Saves instance handle and creates main window.
  14.    MainWndProc() - Processes window messages.
  15.    About() - Processes messages for "About" dialog box.
  16.    MakeHelpPathName() - Derives path name of help file.
  17.  
  18. ****************************************************************************/
  19.  
  20. #include <windows.h>
  21. #include "helpex.h"
  22. #include "helpids.h"
  23.  
  24.  
  25. HWND       hWnd;               /* Handle to main window */
  26. HANDLE     hInst;              /* Handle to instance data*/
  27. FARPROC    lpFilterFunc;
  28. BOOL       bHelp = FALSE;      /* Help mode flag; TRUE = "ON"*/
  29. DWORD      dwCurrentHelpId = HELPID_NONE;  /* Current help context for menus and dialogs */
  30. HCURSOR    hHelpCursor;        /* Cursor displayed when in help mode*/
  31. char       szHelpFileName[EXE_NAME_MAX_SIZE+1];    /* Help file name*/
  32. HANDLE     hAccTable;                              /* handle to accelerator table */
  33. HMENU      hMenuFile, hMenuEdit, hMenuHelp;
  34.  
  35. void MakeHelpPathName(char*);  /* Function deriving help file path */
  36. int FAR PASCAL FilterFunc(int, WORD, DWORD); /* Filter function to detect F1*/
  37. BOOL MyWinHelp(HWND, LPSTR, WORD, DWORD);
  38. void StartDialog(FARPROC, WORD);
  39. void DisplayError(WORD);
  40.  
  41. /****************************************************************************
  42.  
  43.    FUNCTION:   WinMain(HANDLE, HANDLE, LPSTR, int)
  44.  
  45.    PURPOSE:    Calls initialization function, processes message loop.
  46.  
  47. ****************************************************************************/
  48.  
  49. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  50. HANDLE hInstance;
  51. HANDLE hPrevInstance;
  52. LPSTR  lpCmdLine;
  53. int    nCmdShow;
  54. {
  55.    MSG msg;
  56.  
  57.    if (!hPrevInstance)
  58.        if (!InitApplication(hInstance))
  59.        return (FALSE);
  60.  
  61.    if (!InitInstance(hInstance, nCmdShow))
  62.        return (FALSE);
  63.  
  64.    while (GetMessage(&msg, NULL, NULL, NULL)) {
  65.  
  66.       /* Only translate message if it is not an accelerator message */
  67.       if (!TranslateAccelerator(hWnd, hAccTable, &msg)) {
  68.  
  69.           TranslateMessage(&msg);
  70.           DispatchMessage(&msg);
  71.       }
  72.    }
  73.    return (msg.wParam);
  74. }
  75.  
  76.  
  77. /****************************************************************************
  78.  
  79.    FUNCTION:   InitApplication(HANDLE)
  80.  
  81.    PURPOSE:    Initializes window data and registers window class.
  82.  
  83.    RETURNS:    Status of RegisterClass() call.
  84.  
  85. ****************************************************************************/
  86.  
  87. BOOL InitApplication(hInstance)
  88. HANDLE hInstance;
  89. {
  90.    WNDCLASS wc;
  91.  
  92.    wc.style = NULL;
  93.    wc.lpfnWndProc = MainWndProc;
  94.    wc.cbClsExtra = 0;
  95.    wc.cbWndExtra = 0;
  96.    wc.hInstance = hInstance;
  97.    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  98.    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  99.    wc.hbrBackground = COLOR_WINDOW+1;
  100.    wc.lpszMenuName ="HelpexMenu";
  101.    wc.lpszClassName = "HelpexWClass";
  102.  
  103.    return (RegisterClass(&wc));
  104. }
  105.  
  106.  
  107. /****************************************************************************
  108.  
  109.    FUNCTION:   InitInstance(HANDLE, int)
  110.  
  111.    PURPOSE:    Saves instance handle in global variable and creates main 
  112.                window.
  113.  
  114.    RETURNS:    Status of CreateWindow() call.
  115.  
  116. ****************************************************************************/
  117.  
  118. BOOL InitInstance(hInstance, nCmdShow)
  119. HANDLE hInstance;
  120. int    nCmdShow;
  121. {
  122.    FARPROC    lpProcInstance;
  123.    HMENU      hMenu;
  124.  
  125.    hInst = hInstance;
  126.  
  127.    hAccTable = LoadAccelerators(hInst, "HelpexAcc");
  128.  
  129.    hWnd = CreateWindow(
  130.        "HelpexWClass",
  131.        "Help Example ",
  132.        WS_OVERLAPPEDWINDOW,
  133.        CW_USEDEFAULT,
  134.        CW_USEDEFAULT,
  135.        CW_USEDEFAULT,
  136.        CW_USEDEFAULT,
  137.        NULL,
  138.        NULL,
  139.        hInstance,
  140.        NULL
  141.        );
  142.  
  143.    if (!hWnd)
  144.        return (FALSE);
  145.  
  146.    ShowWindow(hWnd, nCmdShow);
  147.    UpdateWindow(hWnd);
  148.  
  149.    EnableMenuItem(GetSubMenu(GetMenu(hWnd), 1), IDM_CLEAR, MF_ENABLED);
  150.  
  151.    MakeHelpPathName(szHelpFileName);
  152.    hHelpCursor = LoadCursor(hInst,"HelpCursor");
  153.  
  154.    lpProcInstance = MakeProcInstance(FilterFunc,hInstance);
  155.    if (lpProcInstance == NULL)
  156.        return (FALSE);
  157.    lpFilterFunc = SetWindowsHook(WH_MSGFILTER,lpProcInstance);
  158.  
  159.    /*
  160.     * Store menu handles in global variables so that we can compare
  161.     * them for context sensitive help later.
  162.     */
  163.    hMenu = GetMenu(hWnd);
  164.    hMenuFile = GetSubMenu(hMenu, 0);
  165.    hMenuEdit = GetSubMenu(hMenu, 1);
  166.    hMenuHelp = GetSubMenu(hMenu, 2);
  167.  
  168.    return (TRUE);
  169.  
  170. }
  171.  
  172.  
  173. /****************************************************************************
  174.  
  175.    FUNCTION:   FilterFunc(int, WORD, DWORD)
  176.  
  177.    PURPOSE:    Checks for the F1 key being pressed while a menu
  178.            or dialog box is displayed.
  179.  
  180.    MESSAGES:
  181.  
  182.        WM_F1DOWN- User defined message posted to main window to indicate
  183.           F1 has been pressed.
  184.  
  185. ****************************************************************************/
  186.  
  187. int FAR PASCAL FilterFunc(nCode, wParam, lParam)
  188. int    nCode;
  189. WORD   wParam;
  190. DWORD  lParam;
  191. {
  192.     LPMSG lpmsg = (LPMSG)lParam;
  193.  
  194.     if ((nCode == MSGF_DIALOGBOX || nCode == MSGF_MENU) && 
  195.          lpmsg->message == WM_KEYDOWN && lpmsg->wParam == VK_F1) {
  196.         PostMessage(hWnd, WM_F1DOWN, nCode, 0L);
  197.     }
  198.  
  199.     DefHookProc(nCode, wParam, lParam, &lpFilterFunc);
  200.  
  201.     return (FALSE);
  202. }
  203.  
  204.  
  205. /****************************************************************************
  206.  
  207.    FUNCTION:   MyWinHelp(HWND, LPSTR, WORD, DWORD)
  208.  
  209.    PURPOSE:    This function may be used instead of WinHelp to 
  210.            make HELP_SETCONTENTS work better.  By using MyWinHelp()
  211.            instead of WinHelp() everywhere, you may send
  212.            HELP_SETCONTENTS to set the contents and not bring up
  213.            Help, and use any WinHelp API (including HELP_CONTENTS)
  214.            without losing the contents that got set.
  215.  
  216. ****************************************************************************/
  217.  
  218. BOOL MyWinHelp(hwnd, lpHelpfile, wCommand, dwData)
  219. HWND     hwnd;
  220. LPSTR    lpHelpfile;
  221. WORD     wCommand;
  222. DWORD    dwData;
  223. {
  224.    static DWORD   ctxContents = (DWORD)-1L;
  225.  
  226.    if (wCommand == HELP_SETCONTENTS) {
  227.       ctxContents = dwData;
  228.       return (TRUE);
  229.    }
  230.  
  231.    if (wCommand == HELP_CONTENTS && ctxContents != (DWORD)-1L) {
  232.       WinHelp(hwnd, lpHelpfile, HELP_CONTEXT, ctxContents);
  233.    }
  234.    else {
  235.       WinHelp(hwnd, lpHelpfile, wCommand, dwData);
  236.    }
  237.  
  238.    if (wCommand != HELP_QUIT && ctxContents != (DWORD)-1L) {
  239.       WinHelp (hwnd, lpHelpfile, HELP_SETCONTENTS, dwData);
  240.    }
  241.  
  242. }
  243.  
  244.  
  245. /****************************************************************************
  246.  
  247.    FUNCTION:   StartDialog(WORD)
  248.  
  249.    PURPOSE:    This function is used to start a dialog with context
  250.            sensitive help.  It assumes that the dialog resource
  251.            id is the same as the number that has been mapped to
  252.            the help context.
  253.  
  254. ****************************************************************************/
  255.  
  256. void StartDialog(lpDialogProc, wDlgId)
  257. FARPROC lpDialogProc;
  258. WORD wDlgId;
  259. {
  260.    FARPROC lpInstanceProc;
  261.  
  262.    dwCurrentHelpId = (DWORD) wDlgId;
  263.  
  264.    lpInstanceProc = MakeProcInstance(lpDialogProc, hInst);
  265.    DialogBox(hInst, 
  266.        MAKEINTRESOURCE(wDlgId), 
  267.        hWnd, 
  268.        lpInstanceProc);
  269.    FreeProcInstance(lpInstanceProc);
  270.  
  271.    dwCurrentHelpId = HELPID_NONE;
  272.  
  273. }
  274.  
  275.  
  276.  
  277. /****************************************************************************
  278.  
  279.    FUNCTION:   DisplayError(WORD)
  280.  
  281.    PURPOSE:    This function is used to display an error message with context
  282.            sensitive help.  It assumes that the error string resource
  283.            id is the same as the number that has been mapped to
  284.            the help context.
  285.  
  286. ****************************************************************************/
  287.  
  288. void DisplayError(wErrId)
  289. WORD wErrId;
  290. {
  291.    char rgchBuf[ERRORSTRING_MAX_SIZE];
  292.  
  293.    dwCurrentHelpId = (DWORD) wErrId;
  294.  
  295.    LoadString(hInst, wErrId, rgchBuf, ERRORSTRING_MAX_SIZE);
  296.    MessageBox(hWnd, rgchBuf, "Help Example", MB_OK);
  297.  
  298.    dwCurrentHelpId = HELPID_NONE;
  299. }
  300.  
  301.  
  302. /****************************************************************************
  303.  
  304.    FUNCTION:   MainWndProc(HWND, UINT, WPARAM, LPARAM)
  305.  
  306.    PURPOSE:    Processes window messages.
  307.  
  308.    MESSAGES:
  309.  
  310.        WM_COMMAND- Application menu item 
  311.        WM_DESTROY- Destroy window
  312.  
  313. ****************************************************************************/
  314.  
  315. long FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
  316. HWND        hWnd;
  317. UINT        message;
  318. WPARAM        wParam;
  319. LPARAM        lParam;
  320. {
  321.  
  322.    switch (message) {
  323.  
  324.        case WM_SYSCOMMAND:
  325.            /* Are we in help mode (Shift-F1)? */
  326.  
  327.            if (bHelp) {
  328.                dwCurrentHelpId =
  329.                    (wParam == SC_RESTORE)      ? (DWORD) HELPID_SYSRESTORE  :
  330.                    (wParam == SC_MOVE)         ? (DWORD) HELPID_SYSMOVE     :
  331.                    (wParam == SC_SIZE)         ? (DWORD) HELPID_SYSSIZE     :
  332.                    (wParam == SC_MINIMIZE)     ? (DWORD) HELPID_SYSMINIMIZE :
  333.                    (wParam == SC_MAXIMIZE)     ? (DWORD) HELPID_SYSMAXIMIZE :
  334.                    (wParam == SC_CLOSE)        ? (DWORD) HELPID_SYSCLOSE    :
  335.                    (wParam == SC_TASKLIST)     ? (DWORD) HELPID_SYSSWITCH   :
  336.                                                (DWORD) HELPID_NONE;
  337.  
  338.                if (dwCurrentHelpId == HELPID_NONE)
  339.                    return (DefWindowProc(hWnd, message, wParam, lParam));
  340.  
  341.                bHelp = FALSE;
  342.                WinHelp(hWnd,szHelpFileName,HELP_CONTEXT,dwCurrentHelpId);
  343.            dwCurrentHelpId = HELPID_NONE;
  344.                break;
  345.            }
  346.  
  347.            return (DefWindowProc(hWnd, message, wParam, lParam));
  348.  
  349.        case WM_COMMAND:
  350.            /* Are we in help mode (Shift-F1)? */
  351.  
  352.            if (bHelp) {
  353.                bHelp = FALSE;
  354.                WinHelp(hWnd,szHelpFileName,HELP_CONTEXT, (DWORD)wParam);
  355.            return NULL;
  356.            }
  357.  
  358.            switch (wParam) {
  359.                case IDM_NEW:
  360.                case IDM_OPEN:
  361.                case IDM_SAVE:
  362.                case IDM_SAVEAS:
  363.                case IDM_PRINT:
  364.                case IDM_UNDO:
  365.                case IDM_CUT:
  366.                case IDM_CLEAR:
  367.                case IDM_COPY:
  368.                case IDM_PASTE:
  369.            DisplayError(ERR_NOT_YET_IMPLEMENTED);
  370.                    break;
  371.  
  372.                case IDM_EXIT:
  373.                    DestroyWindow(hWnd);
  374.                    break;
  375.  
  376.                case IDM_HELP_CONTENTS:
  377.                    WinHelp(hWnd,szHelpFileName,HELP_CONTENTS,0L);
  378.                    break;
  379.  
  380.            case IDM_HELP_KEYBOARD:
  381.            WinHelp(hWnd, szHelpFileName, HELP_COMMAND,
  382.               (DWORD)(LPSTR)"JumpID(`myhelp.hlp',`IDM_HELP_KEYBOARD')");
  383.                    break;
  384.  
  385.            case IDM_HELP_SEARCH:
  386.            WinHelp(hWnd,szHelpFileName,HELP_PARTIALKEY,(DWORD)(LPSTR)"");
  387.            break;
  388.  
  389.                case IDM_HELP_HELP:
  390.            WinHelp(hWnd,szHelpFileName,HELP_HELPONHELP,0L);
  391.                    break;
  392.  
  393.                case IDM_ABOUT:
  394.            StartDialog(About, ABOUTBOX);
  395.                    break;
  396.            
  397.            case IDM_HELP_MULTIKEY:
  398.            StartDialog(Multikey, EDITMULTIKEY);
  399.                    break;
  400.  
  401.                default:
  402.                    return (DefWindowProc(hWnd, message, wParam, lParam));
  403.            }
  404.  
  405.            break;
  406.        
  407.        case WM_LBUTTONDOWN:
  408.        if (bHelp) {
  409.            bHelp = FALSE;
  410.            WinHelp( hWnd, szHelpFileName, HELP_CONTEXT,
  411.             (DWORD) HELPID_EDIT_WINDOW          );
  412.            break;
  413.        }
  414.  
  415.            return (DefWindowProc(hWnd, message, wParam, lParam));
  416.  
  417.        case WM_NCLBUTTONDOWN:
  418.            /* If we are in help mode (Shift-F1) then display context- */
  419.            /* sensitive help for non-client area. */
  420.  
  421.            if (bHelp) {
  422.                dwCurrentHelpId =
  423.                    (wParam == HTCAPTION)     ? (DWORD) HELPID_TITLE_BAR     :
  424.                    (wParam == HTREDUCE)      ? (DWORD) HELPID_MINIMIZE_ICON :
  425.                    (wParam == HTZOOM)        ? (DWORD) HELPID_MAXIMIZE_ICON :
  426.                    (wParam == HTBOTTOM)      ? (DWORD) HELPID_SIZING_BORDER :
  427.                    (wParam == HTBOTTOMLEFT)  ? (DWORD) HELPID_SIZING_BORDER :
  428.                    (wParam == HTBOTTOMRIGHT) ? (DWORD) HELPID_SIZING_BORDER :
  429.                    (wParam == HTTOP)         ? (DWORD) HELPID_SIZING_BORDER :
  430.                    (wParam == HTLEFT)        ? (DWORD) HELPID_SIZING_BORDER :
  431.                    (wParam == HTRIGHT)       ? (DWORD) HELPID_SIZING_BORDER :
  432.                    (wParam == HTTOPLEFT)     ? (DWORD) HELPID_SIZING_BORDER :
  433.                    (wParam == HTTOPRIGHT)    ? (DWORD) HELPID_SIZING_BORDER :
  434.                                                (DWORD) HELPID_NONE;
  435.  
  436.                if (dwCurrentHelpId == HELPID_NONE)
  437.                    return (DefWindowProc(hWnd, message, wParam, lParam));
  438.  
  439.                bHelp = FALSE;
  440.                WinHelp(hWnd,szHelpFileName,HELP_CONTEXT,dwCurrentHelpId);
  441.            dwCurrentHelpId = HELPID_NONE;
  442.                break;
  443.            }
  444.  
  445.            return (DefWindowProc(hWnd, message, wParam, lParam));
  446.  
  447.        case WM_KEYDOWN:
  448.            if (wParam == VK_F1) {
  449.  
  450.                /* If Shift-F1, turn help mode on and set help cursor */ 
  451.  
  452.                if (GetKeyState(VK_SHIFT)<0) {
  453.                    bHelp = TRUE;
  454.                    SetCursor(hHelpCursor);
  455.                    return (DefWindowProc(hWnd, message, wParam, lParam));
  456.                }
  457.  
  458.                /* If F1 without shift, then call up help main index topic */ 
  459.                else {
  460.                    WinHelp(hWnd,szHelpFileName,HELP_CONTENTS,0L);
  461.                }
  462.            }
  463.  
  464.            else if (wParam == VK_ESCAPE && bHelp) {
  465.  
  466.                /* Escape during help mode: turn help mode off */
  467.  
  468.                bHelp = FALSE;
  469.                SetCursor((HCURSOR)GetClassWord(hWnd,GCW_HCURSOR));
  470.            }
  471.  
  472.            break;
  473.  
  474.        case WM_MENUSELECT:
  475.        /*
  476.         * Set dwCurrentHelpId to the Help ID of the menu item that is
  477.         * currently selected.
  478.         */
  479.  
  480.        if (HIWORD(lParam) == 0)               /* no menu selected */
  481.            dwCurrentHelpId = HELPID_NONE;
  482.  
  483.        else if (lParam & MF_POPUP) {               /* pop-up selected */
  484.            if ((HMENU)wParam == hMenuFile)
  485.            dwCurrentHelpId = HELPID_FILE;
  486.            else if ((HMENU)wParam == hMenuEdit)
  487.            dwCurrentHelpId = HELPID_EDIT;
  488.            else if ((HMENU)wParam == hMenuHelp)
  489.            dwCurrentHelpId = HELPID_HELP;
  490.            else
  491.            dwCurrentHelpId = HELPID_SYSTEM;
  492.        }
  493.        else               /* menu item selected */
  494.            dwCurrentHelpId = wParam;
  495.  
  496.        break;
  497.  
  498.  
  499.        case WM_F1DOWN:
  500.        /* If there is a current help context, then */
  501.            /* display it */
  502.  
  503.        if (dwCurrentHelpId != HELPID_NONE) {
  504.  
  505.            DWORD dwHelp = dwCurrentHelpId;
  506.  
  507.            /*******************************************
  508.  
  509.          To provide context sensitive help for 
  510.          individual controls in your dialog boxes,
  511.          include the following code:
  512.  
  513.            if (wParam == MSGF_DIALOGBOX) {
  514.  
  515.            WORD wID = GetWindowWord(GetFocus(), GWW_ID);
  516.            if (wID != IDOK && wID != IDCANCEL)
  517.                dwHelp = (DWORD)wID;
  518.            }
  519.  
  520.            ********************************************/
  521.  
  522.                WinHelp(hWnd, szHelpFileName, HELP_CONTEXT, dwHelp);
  523.  
  524.            /*
  525.             * This call is used to remove the highlighting from
  526.             * the system menu, if necessary.
  527.         */
  528.            DrawMenuBar(hWnd);
  529.        }
  530.  
  531.        break;
  532.  
  533.        case WM_SETCURSOR:
  534.        /*
  535.             * In help mode it is necessary to reset the cursor in response
  536.             * to every WM_SETCURSOR message.Otherwise, by default, Windows
  537.             * will reset the cursor to that of the window class.
  538.         */
  539.  
  540.            if (bHelp) {
  541.                SetCursor(hHelpCursor);
  542.                break;
  543.            }
  544.            return (DefWindowProc(hWnd, message, wParam, lParam));
  545.            break;
  546.  
  547.  
  548.        case WM_INITMENU:
  549.            if (bHelp) {
  550.                SetCursor(hHelpCursor);
  551.            } 
  552.            return (TRUE);
  553.  
  554.        case WM_DESTROY:
  555.            WinHelp(hWnd,szHelpFileName,HELP_QUIT,0L);
  556.            PostQuitMessage(0);
  557.            break;
  558.  
  559.        default:
  560.            return (DefWindowProc(hWnd, message, wParam, lParam));
  561.    }
  562.  
  563.    return (NULL);
  564. }
  565.  
  566.  
  567. /****************************************************************************
  568.  
  569.    FUNCTION:   About(HWND, UINT, WPARAM, LPARAM)
  570.  
  571.    PURPOSE:    Processes messages for "About" dialog box
  572.    
  573.    MESSAGES:
  574.  
  575.        WM_INITDIALOG - Initialize dialog box
  576.        WM_COMMAND- Input received
  577.  
  578. ****************************************************************************/
  579.  
  580. BOOL FAR PASCAL About(hDlg, message, wParam, lParam)
  581. HWND         hDlg;
  582. UINT         message;
  583. WPARAM       wParam;
  584. LPARAM       lParam;
  585. {
  586.    switch (message) {
  587.        case WM_INITDIALOG:
  588.            return (TRUE);
  589.  
  590.        case WM_COMMAND:
  591.            if (wParam == IDOK) {
  592.                EndDialog(hDlg, TRUE);
  593.                return (TRUE);
  594.            }
  595.            break;
  596.    }
  597.  
  598.    return (FALSE);
  599. }
  600.  
  601.  
  602. /****************************************************************************
  603.  
  604.    FUNCTION:   Multikey(HWND, UINT, WPARAM, LPARAM)
  605.  
  606.    PURPOSE:    Processes messages for "Keyword" dialog box.  Sends
  607.            HELP_MULTIKEY commands with the keyword entered in 
  608.            the edit box.
  609.    
  610.    MESSAGES:
  611.  
  612.        WM_INITDIALOG - Initialize dialog box
  613.        WM_COMMAND- Input received
  614.  
  615. ****************************************************************************/
  616.  
  617. BOOL FAR PASCAL Multikey(hDlg, message, wParam, lParam)
  618. HWND         hDlg;
  619. UINT         message;
  620. WPARAM       wParam;
  621. LPARAM       lParam;
  622. {
  623.    char rgchBuf[sizeof(MULTIKEYHELP) + MULTIKEY_MAX_SIZE];
  624.    MULTIKEYHELP FAR * lpMultikey;
  625.  
  626.    switch (message) {
  627.        case WM_INITDIALOG:
  628.        SendDlgItemMessage(hDlg, IDEDITMULTIKEY, WM_SETTEXT, 0, (DWORD)(LPSTR)"Multikey");
  629.            return (TRUE);
  630.  
  631.        case WM_COMMAND:
  632.        switch (wParam) {
  633.  
  634.        case IDOK:
  635.            lpMultikey = (MULTIKEYHELP FAR *) rgchBuf;
  636.            lpMultikey->mkKeylist = 'M';
  637.            SendDlgItemMessage(hDlg, IDEDITMULTIKEY, WM_GETTEXT, 
  638.             MULTIKEY_MAX_SIZE, (DWORD)(LPSTR)lpMultikey->szKeyphrase);
  639.            lpMultikey->mkSize =
  640.           sizeof(MULTIKEYHELP) + lstrlen(lpMultikey->szKeyphrase);
  641.            WinHelp(hWnd, szHelpFileName, HELP_MULTIKEY, (DWORD)lpMultikey);
  642.  
  643.            /* Fall through: */
  644.        case IDCANCEL:
  645.                EndDialog(hDlg, TRUE);
  646.                return (TRUE);
  647.            }
  648.    }
  649.  
  650.    return (FALSE);
  651. }
  652.  
  653. /****************************************************************************
  654.  
  655.    FUNCTION:   MakeHelpPathName
  656.  
  657.    PURPOSE:    HelpEx assumes that the .HLP help file is in the same
  658.                directory as the HelpEx executable.This function derives
  659.                the full path name of the help file from the path of the
  660.                executable.
  661.  
  662. ****************************************************************************/
  663.  
  664. void MakeHelpPathName(szFileName)
  665. char * szFileName;
  666. {
  667.    char *  pcFileName;
  668.    int     nFileNameLen;
  669.  
  670.    nFileNameLen = GetModuleFileName(hInst,szFileName,EXE_NAME_MAX_SIZE);
  671.    pcFileName = szFileName + nFileNameLen;
  672.  
  673.    while (pcFileName > szFileName) {
  674.        if (*pcFileName == '\\' || *pcFileName == ':') {
  675.            *(++pcFileName) = '\0';
  676.            break;
  677.        }
  678.    nFileNameLen--;
  679.    pcFileName--;
  680.    }
  681.  
  682.    if ((nFileNameLen+13) < EXE_NAME_MAX_SIZE) {
  683.        lstrcat(szFileName, "helpex.hlp");
  684.    }
  685.  
  686.    else {
  687.        lstrcat(szFileName, "?");
  688.    }
  689.  
  690.    return;
  691. }
  692.